package com.allenkerr.third.gaussian_blur;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException {
        //模糊半径 100
        test0();

        //模糊半径 0 - 10
//        test1();

        //模糊半径 2，递归执行 10 次
//        test2();
    }

    public static void test0() throws IOException {
        File file = new File("/Users/scw/Downloads/787.jpg");
        BufferedImage img = ImageIO.read(file);
        assert img != null;
        System.out.println("Image Loaded: " + img.getWidth() + "x" + img.getHeight());

        int blurRadius = 100;
        GaussianBlurEffect blurEffect = new GaussianBlurEffect(blurRadius, img);
        String outPath = "/Users/scw/Downloads/out" + blurRadius + ".jpg";
        blurEffect.getBluredImg(outPath);
    }

    public static void test1() throws IOException {
        File file = new File("/Users/scw/Downloads/787.jpg");
        BufferedImage img = ImageIO.read(file);
        assert img != null;
        System.out.println("Image Loaded: " + img.getWidth() + "x" + img.getHeight());

        for (int blurRadius = 0; blurRadius <= 10; blurRadius++) {
            GaussianBlurEffect blurEffect = new GaussianBlurEffect(blurRadius, img);
            String outPath = "/Users/scw/Downloads/out" + blurRadius + ".jpg";
            blurEffect.getBluredImg(outPath);
        }
    }

    public static void test2() throws IOException {
        File file = new File("/Users/scw/Downloads/787.jpg");
        int blurRadius = 2;
        String outPath;
        for (int i = 0; i < 10; i++) {
            BufferedImage img = ImageIO.read(file);
            assert img != null;
            System.out.println("Image Loaded: " + img.getWidth() + "x" + img.getHeight());

            GaussianBlurEffect blurEffect = new GaussianBlurEffect(blurRadius, img);
            outPath = "/Users/scw/Downloads/out_" + i + ".jpg";
            blurEffect.getBluredImg(outPath);

            //对输出文件再次做模糊处理
            file = new File(outPath);
        }
    }
}